// Triples.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int levenshtein(string a, string b, int thr)
{
	register int i, j;
	int dp[101][101] = { {0},{0} };

	for (i = 1;i <= a.size();++i)
		dp[i][0] = i;
	for (j = 1;j <= b.size();++j)
		dp[0][j] = j;

	for (i = 1;i < a.size()+1;++i)
	{
		for (j = 1;j < b.size()+1;++j)
		{
			if (a[i-1] == b[j-1])
				dp[i][j] = dp[i - 1][j - 1];
			else
				dp[i][j] = min(min(dp[i - 1][j] + 1, dp[i][j - 1] + 1), dp[i - 1][j - 1] + 1);
			if (dp[i][j] >= thr)
				continue;
		}
	}
	return dp[a.size()+1][b.size()+1];
}
int main()
{
	ifstream in("dtb.txt");
	ofstream out("dtb.out");
	int N, M, T,num_of=0;
	int counter = 0;
	register int i=0, j=0,k,l;
	vector<vector<string>> cluster1, cluster2;
	string temp;
	in >> N >> M >> T;

	in.ignore();
	for (i = 0;i < N;++i)
	{
		getline(in, temp);
		if (cluster1.size() < temp.size())
			cluster1.resize(temp.size());
		cluster1[temp.size() - 1].push_back(temp);
	}

	for (j = 0;j < M;++j)
	{
		getline(in, temp);
		if (cluster2.size() < temp.size())
			cluster2.resize(temp.size());
		cluster2[temp.size() - 1].push_back(temp);
	}
	
	for (i = 0;i < cluster1.size();++i)
	{
		if (cluster1[i].size() == 0)
			continue;
		for (j = 0;j < cluster1[i].size();++j)
		{
			for (k = i;k<=i+T;++k)
			{
				if (k>cluster2.size()-1)
					break;
				for (l = 0;l < cluster2[k].size();++l)
				{
					if (levenshtein(cluster1[i][j], cluster2[k][l], T) <= T)
						counter++;
				}
			}
		}
	}
	out << counter;
	in.close();
	out.close();
	system("pause");
    return 0;
}